package com.jiaai.cloud.wx.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.jiaai.cloud.base.page.CustomPage;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.wx.entity.TEmp;
import com.jiaai.cloud.wx.mapper.TEmpMapper;
import com.jiaai.cloud.wx.mapper.TPayMapper;
import com.jiaai.cloud.wx.service.ITEmpService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-28
 */
@SuppressWarnings("SpringJavaAutowiringInspection")
@Service
public class TEmpServiceImpl extends ServiceImpl<TEmpMapper, TEmp> implements ITEmpService {

    @Autowired
    private TEmpMapper tEmpMapper;
    @Autowired
    private TPayMapper tPayMapper;

    @Override
    public void deleteLogically(String empid) {
        tEmpMapper.deleteLogically(empid);
    }

    @Override
    public CustomPage<TEmp> selectGroupEmp(Page page, Integer groupid) {
        page.setRecords(tEmpMapper.selectGroupEmp(page,groupid));
        return new CustomPage<TEmp>(page);
    }

    @Override
    @Transactional
    public void deleteLogicallyBatch(String[] empids) {
        for (String empid : empids){
            tPayMapper.logicalDelete(empid);
            tEmpMapper.deleteLogically(empid);
        }
    }

    @Override
    @Transactional
    public void changeGroupBatch(String[] empids, Integer groupid) {
        TEmp tEmp = new TEmp();
        for (String empid : empids){
            tEmp.setEmpid(empid);
            tEmp.setGroupid(groupid);
            tEmpMapper.updateById(tEmp);
        }
    }
}
